<% '菜单生成%>
<%''加载通用函数和数据库连接%>
<!--#include file="../Include/Start.asp"-->

<%
'**************************************************
'函数名：GetMenuJsonByUserID
'作  用：生成某用户对应权限菜单的json串
'参  数：user_id=用户id, res_page_code=资源代码对应字段res_num
'返回值：True/False
'**************************************************
Private Function GetMenuJsonByUserID(UserId, res_page_code)
''查找某个用户对应的权限对应的资源的信息，生成菜单
''Response.Write "--<<<" & UserId & "-----" & resPPath & ">>>---"
	Dim jsonObj_navg_list,jsonObj_navg_list_menu 
	Set jsonObj_navg_list =  jsArray()
	Set jsonObj_navg_list_menu =  jsArray()

	''添加导航信息 
	
 
	Dim rsObjH,strSql
	Set rsObjT = Server.CreateObject("ADODB.Recordset")

 
 

	strSql=""
	''strSql=strSql & " SELECT  DISTINCT  mm.* from ("
	strSql=strSql & " SELECT  DISTINCT mm.* from("''--menu_name, mm.menu_code, mm.res_url, mm.res_ppath  from ("
	strSql=strSql & " SELECT TOP 100  T_RES.menu_name,T_RES.menu_code,T_RES.res_url,T_RES.res_ppath "
	strSql=strSql & " , sel=CASE  WHEN T_RES.res_num ='"&res_page_code&"' THEN 'on' ELSE ''  END "
	strSql=strSql & " FROM T_RES INNER JOIN T_ROLE_RES INNER JOIN T_USER_ROLE  "
	strSql=strSql & " ON T_ROLE_RES.role_id = T_USER_ROLE.role_id ON  T_RES.id = T_ROLE_RES.res_id "
	'''strSql=strSql & " WHERE T_RES.menu_show=1 and T_USER_ROLE.user_id ="&UserId&" "
	strSql=strSql & "  WHERE (T_USER_ROLE.user_id = '"&UserId&"') AND (T_RES.menu_show = 1) "
	strSql=strSql & " ORDER BY T_RES.res_ppath + cast(T_RES.id AS varchar(5)) , T_RES.menu_num "
	strSql=strSql & " ) mm ORDER BY  mm.menu_code ,mm.res_ppath "
	
	
	''Response.Write strSql&"-----<br><br>"
	rsObjT.Open strSql, Conn, 1, 3
	If rsObjT.BOF And rsObjT.EOF Then 
			'nothing
		'end if	 
		'UserID=ReplaceBadChar(Trim(rsObjT("UserID")))
 	else 
 		dim flag
 		flag=false
		Do While Not rsObjT.EOF	      
			if ("0_"=rsObjT("res_ppath") )then 
				if flag then 
					Set	jsonObj_navg_list(Null)("menu") =jsonObj_navg_list_menu
					set jsonObj_navg_list_menu=nothing
					flag = false
				end if 
				 ''Response.Write "<br>"&resPPath&"====="&flag
				Set jsonObj_navg_list(Null) = jsObject()
				jsonObj_navg_list(Null)("txt") = rsObjT("menu_name")
				jsonObj_navg_list(Null)("name") = rsObjT("menu_code")
				jsonObj_navg_list(Null)("href") = rsObjT("res_url")	
				Set jsonObj_navg_list_menu =  jsArray()	
			else 
				flag=true
				Set jsonObj_navg_list_menu(Null) = jsObject()
				jsonObj_navg_list_menu(Null)("txt")= rsObjT("menu_name")
				jsonObj_navg_list_menu(Null)("href")= rsObjT("res_url")
				jsonObj_navg_list_menu(Null)("sel") = rsObjT("sel")	
				if "on"=rsObjT("sel")	then jsonObj_navg_list(Null)("sel") ="on"		
			end if 
			rsObjT.MoveNext 
		Loop 
		if (flag=true) then 
			Set	jsonObj_navg_list(Null)("menu") =jsonObj_navg_list_menu
			set jsonObj_navg_list_menu=nothing
			flag = false
		end if 

	end if 
	rsObjT.close
	Set rsObjT = Nothing 

 '释放数据库链接
	''call CloseConn	 
	Set GetMenuJsonByUserID = jsonObj_navg_list



End Function
%>

<%
	dim respagecode 
  	respagecode=request("respagecode")
	'定义json对象
	Dim jsonObj,jsonObj_user,jsonObj_navg_list,jsonObj_temp
	Set jsonObj = jsObject()
	
	Set jsonObj_user = jsObject()
	''添加用户信息
	jsonObj_user("UserID") = ReplaceBadChar(Trim(Session("UserID"))) 
	jsonObj_user("UserName") =ReplaceBadChar(Trim(Session("UserName")))
	Set jsonObj("customer") = jsonObj_user 	
	
	Set jsonObj_navg_list =  jsArray()
	''添加导航信息
	Set jsonObj("navg_list") = GetMenuJsonByUserID(Session("UserID"),respagecode) 	 
	
	'输出json对象
	jsonObj.Flush
	''Response.Write"--+++++++<br>"
	''Response.Write strSql&"-----"
	
%>
